import lombok.extern.slf4j.Slf4j;

/**
 * @author 管子
 * @date 2025/4/21 20:53
 * @description: ThreadStateTest 类
 */
@Slf4j
public class ThreadStateTest {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.debug("running......"); // NEW
        }, "t1");

        Thread t2 = new Thread(() -> {
            while (true) {
                // RUNNABLE
            }
        }, "t2");
        t2.start();

        Thread t3 = new Thread(() -> {
            log.debug("running......"); // TERMINATED
        }, "t3");
        t3.start();

        Thread t4 = new Thread(() -> {
            synchronized (ThreadStateTest.class) {
                try {
                    Thread.sleep(100000); // :TIME_WAITING
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t4");
        t4.start();

        Thread t5 = new Thread(() -> {
            try {
                t2.join(); // WAITING
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t5");
        t5.start();

        Thread t6 = new Thread(() -> {
            synchronized (ThreadStateTest.class) {
                try {
                    Thread.sleep(100000); // BLOCKED
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t6");
        t6.start();

        Thread.sleep(1000);
        System.out.println("t1: " + t1.getState());
        System.out.println("t2: " + t2.getState());
        System.out.println("t3: " + t3.getState());
        System.out.println("t4: " + t4.getState());
        System.out.println("t5: " + t5.getState());
        System.out.println("t6: " + t6.getState());
    }

}
